import 'package:buy_flutter/net/bean/UserLoginBean.dart';
import 'package:buy_flutter/net/net_config.dart';
import 'package:buy_flutter/router/router_utils.dart';
import 'package:flutter/services.dart';

class UserSharePreference {
  static void addUser(UserLoginBean userLoginBean) async {
    String jwt = userLoginBean.data.jwt;
    try {
      String reslut = await MethodChannel(RouterUtils.METHOD_CHANNEL_KEY)
          .invokeMethod("saveJwt", jwt);
    } catch (e) {

    }

    NetConfig.setJwt(userLoginBean.data.jwt);
  }

  static Future<String> getJwt() async {
    try {
      String reslut = await MethodChannel(RouterUtils.METHOD_CHANNEL_KEY)
          .invokeMethod("getJwt");
      return reslut;
    } catch (e) {
      return "";
      return "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NTQsIm5hbWUiOiJoeXkiLCJtb2JpbGUiOiIxODc5MjExMjc4MSIsImxvZ2luX3RpbWUiOjE2MjIxNjk2MTR9.gH_9EIhFwj81fBe3J-PhZaEPHFaUDDKdSKQbe0fePvs";
    }
  }

  static Future<bool> clear() async {
    return MethodChannel(RouterUtils.METHOD_CHANNEL_KEY)
        .invokeMethod("clearJwt");
  }
}
